package cn.jsj.dispose;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jsj.object.FrontLawyer;
import cn.jsj.pojo.TblLawyer;
import cn.jsj.temporary.data.TemporaryData;
import cn.jsj.utils.ProduceJsonData;
import cn.jsj.utils.SysLogger;

/**
 * 查询律师信息处理类
 * @author LI
 *
 */
public class SearchLawyerInfo extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("进入查询律师信息处理类");

		//获取参数：1.律师姓名 2.职位名
		String lawyerName=request.getParameter("lawyerName").trim();
		lawyerName = new String(lawyerName.getBytes("ISO-8859-1"), "utf-8");
		String positionName=request.getParameter("positionName").trim();
		positionName = new String(positionName.getBytes("ISO-8859-1"), "utf-8");

		//获得限定条件 从第几条开始，一页显示几条
		int startNumb=Integer.parseInt(request.getParameter("start"));
		int totalNumb=Integer.parseInt(request.getParameter("limit"));

		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("获得的参数为--->"+lawyerName+positionName+startNumb+totalNumb);

		//职位编号
		int positionNumber=0;
		//如果职位名不为NULL
		if(positionName.length()!=0){
			//获得职位编号
			cn.jsj.dao.TblUtilsDAO tud=new cn.jsj.dao.TblUtilsDAO();
			positionNumber=tud.getPositionNumber(positionName);
		}

		//新建参数类
		cn.jsj.bgtodb.SearchLawyerInfoProperty slip=new cn.jsj.bgtodb.SearchLawyerInfoProperty();
		slip.setLawyerName(lawyerName);
		slip.setPositionNumber(positionNumber);
		slip.setStartNumb(startNumb);
		slip.setTotalNumb(totalNumb);

		//新建律师信息操作对象
		cn.jsj.dao.TblLawyerDAO tld=new cn.jsj.dao.TblLawyerDAO();
		//获得符合条件的律师信息的条数
		int lawyerInfoNumb=tld.getSearchLawyerInfoNumb(slip);

		//根据条件查询律师信息
		java.util.List<TblLawyer> lawyerList=new java.util.LinkedList<TblLawyer>();
		lawyerList=tld.getSearchLawyerInfo(slip);

		//调试信息
		SysLogger.PrintInfo(lawyerList.size());

		//前台律师信息对象队列
		java.util.List<FrontLawyer> frontLawyerInfo=new java.util.LinkedList<FrontLawyer>();

		//改造成前台需要的律师信息对象
		cn.jsj.object.rebuild.LawyerInfoRebuild lir=new cn.jsj.object.rebuild.LawyerInfoRebuild();
		for(int i=0;i<lawyerList.size();i++){
			cn.jsj.object.FrontLawyer fl=lir.rebuildLawyer(lawyerList.get(i));
			frontLawyerInfo.add(fl);
		}

		//改造成JSON型数据
		ProduceJsonData pjd=new ProduceJsonData();
		String resultData=	pjd.jsonFromList(frontLawyerInfo,lawyerInfoNumb);

		//调试信息
		SysLogger.PrintInfo(resultData);
		//输出到客户端
		java.io.PrintWriter pw=response.getWriter();
		pw.println(resultData);
		pw.flush();
		pw.close();
		}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

}
